from info import models, db
from flask import current_app


# 定义方法，创建管理员对象
def create_superuser(username, password):
    admin = models.User()
    admin.nick_name = username
    admin.mobile = username
    admin.password = password
    admin.is_admin = True

    try:
        db.session.add(admin)
        db.session.commit()
    except Exception as e:
        current_app.logger.error(e)
        return "创建失败！"
    return "创建成功！"


if __name__ == '__main__':
    create_superuser('admin', '123456')
